package news;

import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;

public class NewsSortByDate implements Comparator<News> {

	@Override
	public int compare(News arg0, News arg1) {

		Calendar cal0 = getCalendarForDate(arg0.getDateAsType());
		Calendar cal1 = getCalendarForDate(arg1.getDateAsType());
		
		if(cal0.equals(cal1))
			return -1;
		
		if(cal0.before(cal1))
			return 0;
		
		return 1;		
	}
	
	private Calendar getCalendarForDate(Date date) {
		
		Calendar cal = Calendar.getInstance();	
		cal.set(date.getYear(), date.getMonth(), date.getDay());		
		return cal;
	}
}
